// pages/add/add.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    setData: "",
    hidden: false,
    showadd: true,
    projectImg: ""
  },
  chooseImage: function() {
    const that = this
    wx.chooseImage({
      sizeType: ['original', 'conpressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        const tempFilePaths = res.tempFilePaths
        wx.uploadFile({
          url: 'http://123.206.228.246:50080/wxone/goods/uploadImage',
          filePath: tempFilePaths[0],
          name: 'multFile',
          success(res) {
            // console.log(res.data)
            var imgObject = JSON.parse(res.data)
            var imgUrl = imgObject.data
            console.log("http://123.206.228.246:50080/wxone/" + imgUrl)
            that.setData({
              showadd: false,
              projectImg: imgUrl,
            })

          }
        })
      }
    })
  },
  
  formSubmit: function (e) {
    console.log(e)
    wx.request({
      url: 'http://123.206.228.246:50080/wxone/goods/add',
      method: 'POST',
      data: {
        name: e.detail.value.projectName,
        price: e.detail.value.projectPrice,
        image: e.detail.value.image,
        detail: e.detail.value.projectDetail
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: (res) => {
        console.log(res)
        this.setData({
          useData: res.data.data
        })
      }
    })
    wx.showToast({
      title: '添加成功',
      icon: 'success',
      duration: 2000,
      success: function () {
        wx.reLaunch({
          url: '../index/index',
          success: function (res) { },
          fail: function (res) { },
          complete: function (res) { },
        })
      }
    })

  }

})